﻿using System.Diagnostics;

namespace HamcoWcs.Service.Common
{
    public class CmdHelper
    {
        public static void ExcuteCommand(string command)
        {
            var processInfo = new ProcessStartInfo()
            {
                FileName = "cmd.exe",
                Arguments = $"/C {command}",
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardOutput = true,
            };

            using (var process = new Process())
            {
                process.StartInfo = processInfo;
                //process.OutputDataReceived += (sender, e) => MessageBox.Show(e.Data);
                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();

            }
        }

        public static void ExcuteCommand(string command, string workPath)
        {
            var processInfo = new ProcessStartInfo()
            {
                FileName = "cmd.exe",
                Arguments = $"/C {command}",
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                WorkingDirectory = workPath,
            };

            using (var process = new Process())
            {
                process.StartInfo = processInfo;
                //process.OutputDataReceived += (sender, e) => MessageBox.Show(e.Data);
                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();
            }
        }
    }
}
